import { Controller } from "../../mvc/core/Controller";
import { IView } from "../../mvc/interfaces/IView";
import { CrossCityIncomeModule } from "../../../modules/CrossCityIncomeModule";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { GameProxy } from "../mvc/GameProxy";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SCrossCityIncomeInfo } from "../../../Message/Public/SCrossCityIncomeInfo";
import { DataEvent } from "../events/DataEvent";
//class CrossCityIncomeController
    
    export  class CrossCityIncomeController extends Controller
    {
       

        public /* override */ get view(): IView
        {
            if (!this._moduleView) 
            {
                this._moduleView = new CrossCityIncomeModule();
            }
            return this._moduleView;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.CrossMainCity_IncomeView_Open, this.openViewHander);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicSTGetIncomeBack, this.onGetWeekIncomeInfoSuccess);
            return;
        }

        /* internal  */getIncomeResultHander(): void
        {
            this.view.show();
            this._moduleView.updateInfo();
            return;
        }

        /* internal  */openViewHander(arg1: Object /* flash.events.Event */): void
        {
            if (this._moduleView && !this._moduleView.isHide) 
            {
                return;
            }
            GameProxy.crossCityIncomeProxy.getCrossCityIncomeInfo();
            return;
        }

        /* internal  */onGetWeekIncomeInfoSuccess(arg1: MessageBlock): void
        {
            var loc1=null;
            var loc2=null;
            var loc3;
            loc1 = (loc3 = arg1.messageBase as SCrossCityIncomeInfo).thisWeekInfo;
            loc2 = loc3.lastWeekInfo;
            cache.crossCityIncome.setThisWeekInfos(loc1);
            cache.crossCityIncome.setPreWeekInfos(loc2);
            this.getIncomeResultHander();
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossMainCity_IncomeInfoServerBack));
            return;
        }

        private /* var */_moduleView: CrossCityIncomeModule;
    }
